#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N = 2e5 + 10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
int n;
int st[N];
void solve() {
	string s;
	cin >> s;
	vector<vector<int>> pos(10);

	for (int i = 0; i < s.length(); i++) {
		pos[s[i] - '0'].push_back(i);
	}
	int cur = -1;
	vector<int> cnt(10);

	for (int i = 0; i < 10; i++) {
		for (int p : pos[i]) {
			if (p > cur) {
				cur = p;
				cnt[i]++;
			} else cnt[min(i + 1, 9)]++;
		}
	}

	for (int i = 0; i < 10; i++) {
		while (cnt[i]--) cout << i;
	}
	cout << "\n";

}
int main() {
	close();
	int T;
	cin >> T;
	while (T--) solve();
	return 0;
}

